package top.songxs.gmall.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.songxs.gmall.common.result.Result;
import top.songxs.gmall.common.result.ResultCodeEnum;
import top.songxs.gmall.product.dto.SpuInfoDto;
import top.songxs.gmall.product.entity.SpuInfo;
import top.songxs.gmall.product.service.SpuInfoService;

@RestController
@RequestMapping("admin/product")
public class SpuInfoController {
    @Autowired
    private SpuInfoService spuInfoService;
    //http://api.gmall.com/admin/product/{page}/{limit}?category3Id=61
    @GetMapping("/{page}/{limit}")
    public Result<Page<SpuInfo>> findSupInfoByPage(@PathVariable("page") Integer pageNum, @PathVariable("limit") Integer pageSize,
                                          @RequestParam("category3Id") Long category3Id
                                          ){
     Page<SpuInfo> page =    spuInfoService.findSpuInfoByPage(pageNum,pageSize, category3Id);

        return Result.build(page, ResultCodeEnum.SUCCESS);

    }

    //http://api.gmall.com/admin/product/saveSpuInfo
    @PostMapping("saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfoDto spuInfoDto){
        spuInfoService.saveSpuInfo(spuInfoDto);
        return Result.ok();
    }

}
